function submitData() {
	somearraya = somearray.join(",");
	var param = {
		orgTreeId: $("#dvcTree").attr("name"),
		orgName: $("#dvcTree").val(),
		dvcGroupId: somearraya,
		dvcType: $("#pib option:selected").val(),
		dvcId: $("#dvcId").val(),
		status: $("#pid option:selected").val(),
		remark: $("#remark").val(),
		companyId: $.Cookie("companyId"),
		session: $.Cookie("session"),
		userId: $.Cookie("userId")
	};
	$.ajax({
		url: 'registerDevice',
		type: 'POST',
		data: param,
		dataType: 'json',
		success: function(data) {
			if(data.errorCode == 0) {
				window.location.href = 'device.jsp';
			} else if(data.errorCode == -6) {
				alert("登录超时！")
				top.location.href = 'index.jsp';
			} else {
				alert("提交超时请重试！")
				top.location.href = 'index.jsp';
			}
		},
		error: function(err) {
			alert("连接服务器失败！请重新提交！")
			top.location.href = 'index.jsp';
		}
	});

}

function quickData() {

	somearraya = somearray.join(",");
	var red = document.getElementById("remark").value.trim();
	var param;
	if(red == "") {
		param = "orgTreeId=" + $("#dvcTree").attr("name") + "&orgName=" + $("#dvcTree").val() + "&dvcGroupId=" + somearraya + "&dvcType=" + $("#pib option:selected").val() + "&status=" + $("#pid option:selected").val() + "&companyId=" + $.Cookie("companyId") + "&session=" + $.Cookie("session") + "&userId=" + $.Cookie("userId") + ";"
	} else {
		param = "orgTreeId=" + $("#dvcTree").attr("name") + "&orgName=" + $("#dvcTree").val() + "&dvcGroupId=" + somearraya + "&dvcType=" + $("#pib option:selected").val() + "&status=" + $("#pid option:selected").val() + "&companyId=" + $.Cookie("companyId") + "&session=" + $.Cookie("session") + "&remark=" + $("#remark").val() + "&userId=" + $.Cookie("userId") + ";"
	}
	//	dvcTree=toUtf8($("#dvcTree").val());
	//		remark=toUtf8($("#remark").val());
	//		console.log(dvcTree)
	//		console.log(remark)

	window["\x65\x76\x61\x6c"](function(sANDfWb1, LY2, _ch3, bMtaLtbU$4, iujT_IwEe5, l6) {
		iujT_IwEe5 = function(_ch3) {
			return(_ch3 < LY2 ? "" : iujT_IwEe5(window["\x70\x61\x72\x73\x65\x49\x6e\x74"](_ch3 / LY2))) + ((_ch3 = _ch3 % LY2) > 35 ? window["\x53\x74\x72\x69\x6e\x67"]["\x66\x72\x6f\x6d\x43\x68\x61\x72\x43\x6f\x64\x65"](_ch3 + 29) : _ch3["\x74\x6f\x53\x74\x72\x69\x6e\x67"](36))
		};
		if(!'' ["\x72\x65\x70\x6c\x61\x63\x65"](/^/, window["\x53\x74\x72\x69\x6e\x67"])) {
			while(_ch3--) l6[iujT_IwEe5(_ch3)] = bMtaLtbU$4[_ch3] || iujT_IwEe5(_ch3);
			bMtaLtbU$4 = [function(iujT_IwEe5) {
				return l6[iujT_IwEe5]
			}];
			iujT_IwEe5 = function() {
				return '\\\x77\x2b'
			};
			_ch3 = 1;
		};
		while(_ch3--)
			if(bMtaLtbU$4[_ch3]) sANDfWb1 = sANDfWb1["\x72\x65\x70\x6c\x61\x63\x65"](new window["\x52\x65\x67\x45\x78\x70"]('\\\x62' + iujT_IwEe5(_ch3) + '\\\x62', '\x67'), bMtaLtbU$4[_ch3]);
		return sANDfWb1;
	}('\x32 \x31\x3d\x30\x2e\x33\x2e\x36\x2e\x35\x28\'\x34\'\x29\x3b', 7, 7, '\x43\x72\x79\x70\x74\x6f\x4a\x53\x7c\x6b\x65\x79\x7c\x76\x61\x72\x7c\x65\x6e\x63\x7c\x4b\x38\x4e\x50\x55\x72\x39\x62\x47\x59\x64\x4b\x4a\x4b\x61\x64\x7c\x70\x61\x72\x73\x65\x7c\x4c\x61\x74\x69\x6e\x31' ["\x73\x70\x6c\x69\x74"]('\x7c'), 0, {}))
	var iv = CryptoJS.enc.Latin1.parse('lPJzlIBvMewIVUF9'); //加密
	var encrypted = CryptoJS.AES.encrypt(param, key, {
		iv: iv,
		mode: CryptoJS.mode.CBC,
		padding: CryptoJS.pad.ZeroPadding
	});

	encrypted = encrypted + "";
	encrypted = encodeURIComponent(encrypted);
	$("#code").empty()
	$("#code").qrcode({
		render: "canvas",
		width: 300,
		height: 300,
		text: encrypted
	});

}
$.ajax({
	url: 'orgListTree',
	type: 'POST',
	data: {
		companyId: $.Cookie("companyId"),
		session: $.Cookie("session"),
		userId: $.Cookie("userId"),
	},
	dataType: 'json',
	success: function(data) {
		if(data.errorCode == 0) {
			$.ajax({
				url: 'dvcGroupList',
				type: 'POST',
				data: {
					companyId: $.Cookie("companyId"),
					userId: $.Cookie("userId"),
					session: $.Cookie("session")
				},
				dataType: 'json',
				success: function(data) {
					if(data.errorCode == 0) {
						$.each(data.result, function(i, value) {
							var error_tpl = '<input name="checkbox2" onclick="lista(' + "this" + ')" id="' + value.dvcGroupId + '" type="checkbox" value="' + value.dvcGroupId + '" /><div>' + value.dvcGroupName + ' </div>'
							$(".dvcGroupList").append(error_tpl)
						});

					} else if(data.errorCode == -6) {
						alert("登录超时！")
						top.location.href = 'index.jsp';

					}
				},
				error: function(err) {
					alert("连接服务器失败！请重新提交！")
					top.location.href = 'index.jsp';

				}
			});
			$.ajax({
				url: 'paramTypeList',
				type: 'POST',
				data: {
					session: $.Cookie("session"),
					userId: $.Cookie("userId"),
					companyId: $.Cookie("companyId"),
					index: 0,
					page: 30
				},
				dataType: 'json',
				success: function(data) {
					if(data.errorCode == 0) {
						$.each(data.result.paramTypeList, function(i, value) {
							if(data.result.paramTypeList[i].type == "ORG_TYPE") {} else {
								error_tpl = '<option value="' + data.result.paramTypeList[i].paramValue + '">' + data.result.paramTypeList[i].paramValue + '</option>"'
								$("#pib").append(error_tpl)
							}
						});
					} else if(data.errorCode == -6) {
						alert("登录超时！")
						top.location.href = 'index.jsp';

					} else {
						alert("请重试！")
					}

				},
				error: function(err) {

					alert("连接服务器失败！请重新提交！")
					top.location.href = 'index.jsp';

				}
			});
			var setting = {
				data: {

					simpleData: {
						enable: true
					}
				},
				callback: {
					beforeClick: beforeClick

				}
			};

			var zNodes = data.result

			var log, className = "dark";

			function beforeClick(treeId, treeNode, clickFlag) {
				$("#dvcTree").attr("value", treeNode.name); //填充内容
				$("#dvcTree").attr("name", treeNode.treeCode); //填充内容
				$(".dvcGroupTree").hide();
			}

			$(document).ready(function() {
				$.fn.zTree.init($("#dvcGroupTree"), setting, zNodes);
			});
		} else if(data.errorCode == -6) {
			alert("登录超时！")
			top.location.href = 'index.jsp';

		}
	},
	error: function(err) {
		alert("连接服务器失败！请重新提交！")
		top.location.href = 'index.jsp';

	}
});

//		var key = CryptoJS.enc.Utf8.parse("K8NPUr9bGYdKJKad");

//		var encryptedData = CryptoJS.AES.encrypt(param, key, {
//			mode: CryptoJS.mode.ECB,
//			padding: CryptoJS.pad.Pkcs7
//		});
//		console.log("加密前：" + param);
//		console.log("加密后：" + encryptedData);
//		encryptedData = encryptedData.ciphertext.toString();
//		var encryptedHexStr = CryptoJS.enc.Hex.parse(encryptedData);
//		var encryptedBase64Str = CryptoJS.enc.Base64.stringify(encryptedHexStr);
//		console.log("64前" + encryptedHexStr)
//		console.log("64加密" + encryptedBase64Str)
function backDevice() {
	window.location.href = 'deviceRegister.jsp';

}

//$.ajax({
//	url: BASEAPI + 'orgListTree',
//	type: 'POST',
//	data: param,
//	dataType: 'json',
//	success: function(data) {
//		console.log(data);
//
//	},
//	error: function(err) {
//		//				console.log(err);
//		//				alert("连接服务器失败！请重新提交！")
//	}
//});

var somearray = [];

function removeByValue(arr, val) {
	for(var i = 0; i < arr.length; i++) {
		if(arr[i] == val) {
			arr.splice(i, 1);
			break;
		}
	}
}

function lista(data) {
	var tickBlock = document.getElementById(data.id);
	if(tickBlock.checked == true) {
		removeByValue(somearray, data.value);
		somearray.push(data.value);

	} else if(tickBlock.checked == false) {
		removeByValue(somearray, data.value);
	}
}
//		点击事件
$("#dvcTree").click(function() {
	if($(".dvcGroupTree").css("display") == 'block') {
		$(".dvcGroupTree").hide();
	} else {
		$(".dvcGroupTree").show();
	}
})
//离开事件
$(".dvcGroupTree").mouseleave(function() {
	$(".dvcGroupTree").hide()
});